package Classes.GameViews.ViewPanels
{
	import Classes.GameViews.ViewScenes.VS_Main;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;

	public class VP_NPCDialog extends ViewPanel
	{
		private static var _instance:VP_NPCDialog;
		
		private var _interfaceUI:Sprite;
		private var callFun:Function;
		
		public function VP_NPCDialog()
		{
			init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("NPCDialogue_v") as Class);
			this.addChild(this._interfaceUI);
			this.addListener();
		}
		
		public function setDialog(icon:DisplayObject=null,npcTxt:String="",callBackFun:Function=null):void
		{
			callFun=callBackFun;
			this._interfaceUI["setNPCInfo"](icon,npcTxt);
		}
		
		/**
		 * 打开NPC对话框 
		 */		
		public function openNpc():void
		{
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		private function addListener():void
		{
			this.addEventListener("npcBtnEvent",clickHandler);
		}
		
		private function clickHandler(e:Event):void
		{
			if(callFun==null)
			{
				this.closeWin();
			}else{
				callFun();
			}
		}
		
		/**
		 *关闭界面 
		 */		
		public function closeWin():void
		{
			this.close();
		}
		
		
		public static function get instance():VP_NPCDialog
		{
			if(!_instance)_instance=new VP_NPCDialog();
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
	}
}